<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
    <c:set var="ctx" value="${pageContext.request.contextPath}" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>变更记录</title>
    <jsp:include page="../../import.jsp" flush="true" />
</head>

<body class="iframeBody">
<div class="Wrapper">
</div>
<div id="ligergrid1" class="sq-grid"></div>
<c:if test="${isFileMdf==1 }">
    <div class="fieldset1 tabel_col tabel_col_s clearFix">
        <div class="sqPanel">
            <div class="sqPanel_head inL">
                <span>变更资料</span>
                <span class="btns"><span class="sq-button sq-button-round" onclick="downloadMfrFileByUrl();">打包下载</span></span>
            </div>
            <div class="sqPanel_body">
                <div id="mfrFileInfoCfgGrid" class="sq-grid"></div>
            </div>
        </div>
    </div>
</c:if>
</body>

<script type="text/javascript">
    var grid = null;
    var modId;
    var isFileMdf;
    $(function () {
        modId = '${modId}';
        isFileMdf = '${isFileMdf}';
        var _url = '<%=path%>/mfr/mfrinfomoddtl/initList.do?modId=' + modId ;
        $("#ligergrid1").ligerGrid({
            url: _url,
            method : 'get',
            columns: [
                { display: '变更备注', name: 'rlRem', width: '60%' },
                { display: '变更前', name: 'modConBef', width: '20%' },
                { display: '变更后', name: 'modConAft', width: '20%' },
                //{ display: '操作', name: 'modTypCd', width: '20%' },
            ],
            pageSize:10,
            root:'rows',
            record:'total',
            hideLoadButton : true,
            width: '100%',
           // height:'100%',
           // heightDiff:-2,
            rownumbers:true,
        });
        grid = liger.get("ligergrid1");
        if(isFileMdf && isFileMdf == 1){
            initMfrFileInfoCfgGrid()
        }

    });

    /**
     * 初始化附件
     */
    function initMfrFileInfoCfgGrid(){

        //资料配置明细Grid
        mfrFileInfoCfgGrid = $("#mfrFileInfoCfgGrid").ligerGrid({
            url: '<%=path%>/mfr/mfrinfomoddtl/initMfrFileInfoApplyList.do?modId='+modId,
            method: 'get',
            columns: [
                {display: '变更资料名称', name: 'rlRem',align: 'left', minWidth: 100, enabledSort: false},
                {display: '变更前', name: 'filesBef',align: 'left', minWidth: 100, enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        if(value){
                            var h;
                            for(var i in rowdata.filesBef){
                               if(rowdata.filesBef[i]){
                                   h='<a href="javascript:uploadFileByUrl(';
                                   h+="'"+rowdata.filesBef[i].filePath+"'";
                                   h+=",'"+rowdata.filesBef[i].fileNm+"'";
                                   h+=')">'+rowdata.filesBef[i].fileNm+'</a>'
                                   h+='</n>'
                               }
                            }
                            return h;
                        }
                    }
                },
                {display: '变更后', name: 'filesAft',align: 'left', minWidth: 100, enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        if(value){
                            var h;
                            for(var i in rowdata.filesAft){
                                if(rowdata.filesAft[i]){
                                    h='<a href="javascript:uploadFileByUrl(';
                                    h+="'"+rowdata.filesAft[i].filePath+"'";
                                    h+=",'"+rowdata.filesAft[i].fileNm+"'";
                                    h+=')">'+rowdata.filesAft[i].fileNm+'</a>'
                                    h+='</n>'
                                }
                            }
                            return h;
                        }
                    }
                },
            ],
            root: 'rows',
            hideLoadButton : true,
            width: '100%',
            height: '100%',
            isScroll: false,
            rownumbers:true,  //显示序号
            checkbox: false,
            allowUnSelectRow:true,
            alternatingRow: false,
            frozen: false,
            usePager: false,
            onAfterShowData: function ()
            {
                $('#mfrFileInfoCfgGrid').rowspan('rlRem');
                $('#mfrFileInfoCfgGrid').rowspan('filesBef');
                $('#mfrFileInfoCfgGrid').rowspan('filesAft');
            },
        });
    }

    function downloadMfrFileByUrl() {
        var data = mfrFileInfoCfgGrid.getData();
        //var files = [];
        var ids = [];
        for (var i = 0; i < data.length; i++) {
            var map = {};
            if(StringUtils.isNotEmpty(data[i].fileId)){
                ids.push(data[i].fileId);
            }
        }
        var actoinURL = '<%=path%>/system/sysulfilesrec/zipDownloadById.do?';
        var form = $("<form>");
        $('body').append(form);
        form.attr('style','display:none');
        form.attr('target','');
        form.attr('method','post');
        form.attr('action',actoinURL);//下载文件的请求路径
        var input = $('<input>');
        input.attr('type','hidden');
        input.attr('name','ids');
        input.attr('value',JSON.stringify(ids));
        form.append(input);
        form.submit();
    }

    //图片展示
    function showImg(e){
        e.preventDefault();
        var href = $(e.target).attr('src');
        if(!href){
            return;
        }
        if(SQ.regs.img.test(href)){
            var imgSrc = $(e.target).attr('src'),
                imgTit = $(e.target).attr('title');
            window.__ImgSrc = imgSrc;
            window.__ImgTit = imgTit;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        }
    }

    function uploadFileByUrl(_url,_name){
        if(SQ.regs.img.test(_name)){
            //SQ.imgPreview(_url);
            //SQ.imgPreview(_url, true);
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        }else{
            window.open(_url);
        }
    }

</script>

</html>